<?php

include(dirname(__FILE__).'/../../bootstrap/functional.php');

$browser = new BlogTestFunctional(new sfBrowser());
$browser->loadFixtures();
$browser->
  get('/en')->

  with('request')->begin()->
    isParameter('module', 'blog')->
    isParameter('action', 'index')->
  end()->

  with('response')->begin()->
    isStatusCode(200)->
    isValid(true)->
  end()->
  
  click('.post')->
  
  with('request')->begin()->
    isParameter('module', 'blog')->
    isParameter('action', 'show')->
  end()->

  with('response')->begin()->
    isStatusCode(200)->
    isValid(true)->
  end()->
  
  click('#add_comment_form input[type="submit"]', array('blog_comment' => array(
    'name' => 'Hugo',
    'email' => 'hugo'
  )), array('_with_csrf' => true))->
  
  with('form')->hasErrors(true)->
  
  click('#add_comment_form input[type="submit"]', array('blog_comment' => array(
    'name' => 'Hugo',
    'email' => 'hugo@example.com',
    'source_content' => 'Wow this is a great article !!!',
    'follow_by_email' => true
  )), array('_with_csrf' => true))->
  
  with('form')->hasErrors(false)->
  with('mailer')->hasSent(1)->
  with('response')->isRedirected()->
  followRedirect()->
  with('response')->isValid(true)->

  // Unpublished posts are not accessible
  get('/en/blog/unpublished-blog-post')->
  with('response')->isStatusCode(404)->
  
  get('/en/blog/unpublished-post')->
  with('response')->isStatusCode(404)->
  
  // Click on a category
  get('/fr/blog/theme/php-afup')->
  
  with('request')->begin()->
    isParameter('module', 'blog')->
    isParameter('action', 'byCategory')->
  end()->
  
  with('response')->isValid(true)->
  
  // RSS category
  get('/fr/rss/php-afup.atom')->
  
  with('request')->begin()->
    isParameter('module', 'blog')->
    isParameter('action', 'byCategory')->
    isFormat('atom')->
  end()->
  
  with('response')->isValid()->
  
  // RSS last posts
  get('/fr/rss/posts.atom')->
  
  with('request')->begin()->
    isParameter('module', 'blog')->
    isParameter('action', 'index')->
    isFormat('atom')->
  end()->
  
  with('response')->isValid()
;